<?php

/**
 * ecshop ERP v1.0
 * ----------------------------------------------------------------------------
 * http://www.phpally.com
 * Jacklee的博客 致力于php技术
 * ----------------------------------------------------------------------------
 * 作者: Jacklee
 * 邮箱: jack349392900@gmail.com
 * 创建时间: 2013-11-18
 * 最后修改时间: 2013-11-18
 */

/**
 * 产生$num位的由0组成的字符串，如$num=2，返回"00"
 */
function gen_zero_str($num=0)
{
	$res="";
	if($num==0){
		return $res; 
	}
	for($i=1;$i<=$num;$i++)
	{
		$res.="0";
	}
	return $res;
}

/**
 * 格式化编码.
 * @param
 * $code 小于5位的整数
 * @Return 5位的字符串。例如123，返回00123
 */

function format_code($code)
{
	if(!is_int($code)){	
		return false;
	}
	else{
		$code=strval($code);
		if(strlen($code)<5)
		{
			$code=gen_zero_str(5-strlen($code)).$code;
		}		
	}
	return $code;	
}

function get_admin($user_id='')
{
	if(empty($user_id))
	{
		$sql="select user_id,user_name from ".$GLOBALS['ecs']->table('admin_user')." where 1";
		return $GLOBALS['db']->getAll($sql);
	}
	else{
		$sql="select user_id,user_name from ".$GLOBALS['ecs']->table('admin_user')." where user_id='".$user_id."'";
		return $GLOBALS['db']->getRow($sql);		
	}
}


/**
 * 获取管理员ID
 */
function erp_get_admin_id()
{
	$user_id=!empty($_COOKIE['ECSCP']['admin_id'])? $_COOKIE['ECSCP']['admin_id']:'-1';
	$user_id=isset($_SESSION['admin_id'])? $_SESSION['admin_id'] : $user_id;
	return $user_id;
}




?>